import { useCommon } from "@/stores/Common"
import { useDoctor } from "@/stores/Doctor"

import { isReactive, isReadonly, isRef, reactive, toRefs } from "vue"
import { validateCode } from "@/utils/Validate"

const CommonStore = useCommon()
const DS = useDoctor()
const { SelfDeviceOptions, SecondLeafArr, currentPermissionLeafArr } = toRefs(CommonStore)

// console.log(isReadonly(SelfDeviceOptions));
// console.log(isReadonly(SecondLeafArr));
// console.log(isReadonly(currentPermissionLeafArr));



export const searchConfig = reactive({
    name: {
        component: 'AInput',
        label: '姓名',
        attrs: {
            allowClear: true,
            placeholder: '姓名',
            style: {
                width: '100%'
            }
        }
    },
    departmentWard: {
        component: 'ACascader',
        label: '科室',
        attrs: {
            allowClear: true,
            placeholder: '科室',
            changeOnSelect: true,
            options: CommonStore.department === '检验科' ? SecondLeafArr : currentPermissionLeafArr,
            style: {
                width: '100%'
            }
        }
    },
    sex: {
        component: 'ASelect',
        label: '性别',
        attrs: {
            options: [
                { label: '男', value: '男' },
                { label: '女', value: '女' },
            ],
            style: {
                width: '100%'
            }
        }
    }
})

export const searchSelfConfig = {
    name: {
        component: 'AInput',
        label: '姓名',
        attrs: {
            allowClear: true,
            placeholder: '姓名',
            style: {
                width: '100%'
            }
        }
    },
    sex: {
        component: 'ASelect',
        label: '性别',
        attrs: {
            options: [
                { label: '男', value: '男' },
                { label: '女', value: '女' },
            ],
            style: {
                width: '100%'
            }
        }
    }
}

export const addConfig = reactive({
    name: {
        component: 'AInput',
        label: '姓名',
        attrs: {
            allowClear: true,
            placeholder: '姓名',
            style: {
                width: '100%'
            }
        },
        rules: [{ required: true, message: '请输入姓名', trigger: 'blur' }]
    },
    departmentWard: {
        component: 'ACascader',
        label: '科室',
        attrs: {
            allowClear: true,
            placeholder: '科室',
            options: SecondLeafArr,
            style: {
                width: '100%'
            }
        },
        rules: [{ required: true, message: '请输入科室', trigger: 'change' }]
    },
    sex: {
        component: 'ASelect',
        label: '性别',
        attrs: {
            options: [
                { label: '男', value: '男' },
                { label: '女', value: '女' },
            ],
            style: {
                width: '100%'
            }
        },
        rules: [{ required: true, message: '请选择性别', trigger: 'blur' }]
    },
    info: {
        component: 'AInput',
        label: '码录',
        attrs: {
            // disabled: true
            allowClear: true,
            placeholder: '码录',
            style: {
                width: '100%'
            }
        },
        // slotLabel: {
        //     component: 'a',
        //     attrs: {
        //         value: '码录 随机码',
        //         onClick: () => {
        //             DS.addForm.info = RandomTenString()
        //         },
        //     }
        // },
        rules: [{ required: true, validator: validateCode, trigger: 'blur' }]
    },
    serials: {
        component: 'ASelect',
        label: '可控设备',
        attrs: {
            allowClear: true,
            placeholder: '可控设备',
            options: SelfDeviceOptions,
            mode: 'multiple',
            style: {
                width: '100%'
            }
        },
        rules: [{ required: true, message: '请选择可控设备', trigger: 'blur' }]
    }
})

export const addSelfConfig = reactive({
    name: {
        component: 'AInput',
        label: '姓名',
        attrs: {
            allowClear: true,
            placeholder: '姓名',
            style: {
                width: '100%'
            }
        },
        rules: [{ required: true, message: '请输入姓名', trigger: 'blur' }]
    },
    departmentWard: {
        component: 'ACascader',
        label: '科室',
        attrs: {
            allowClear: true,
            placeholder: '科室',
            options: currentPermissionLeafArr,
            style: {
                width: '100%'
            }
        },
        rules: [{ required: true, message: '请输入科室', trigger: 'change' }]
    },
    sex: {
        component: 'ASelect',
        label: '性别',
        attrs: {
            options: [
                { label: '男', value: '男' },
                { label: '女', value: '女' },
            ],
            style: {
                width: '100%'
            }
        },
        rules: [{ required: true, message: '请选择性别', trigger: 'blur' }]
    },
    info: {
        component: 'AInput',
        label: '码录',
        attrs: {
            // disabled: true
            allowClear: true,
            placeholder: '码录',
            style: {
                width: '100%'
            }
        },
        // slotLabel: {
        //     component: 'a',
        //     attrs: {
        //         value: '码录 随机码',
        //         onClick: () => {
        //             DS.addForm.info = RandomTenString()
        //         },
        //     }
        // },
        rules: [{ required: true, message: '请生成电子码', trigger: 'blur' }]
    },
    serials: {
        component: 'ASelect',
        label: '可控设备',
        attrs: {
            allowClear: true,
            placeholder: '可控设备',
            options: SelfDeviceOptions,
            mode: 'multiple',
            style: {
                width: '100%'
            }
        },
        rules: [{ required: true, message: '请选择可控设备', trigger: 'blur' }]
    }
})



export const editConfig = reactive({
    name: {
        component: 'AInput',
        label: '姓名',
        attrs: {
            allowClear: true,
            placeholder: '姓名',
            style: {
                width: '100%'
            }
        },
        rules: [{ required: true, message: '请输入姓名', trigger: 'blur' }]
    },
    departmentWard: {
        component: 'ACascader',
        label: '科室',
        attrs: {
            allowClear: true,
            placeholder: '科室',
            options: SecondLeafArr,
            style: {
                width: '100%'
            }
        },
        rules: [{ required: true, message: '请选择科室', trigger: 'change' }]
    },
    sex: {
        component: 'ASelect',
        label: '性别',
        attrs: {
            options: [
                { label: '男', value: '男' },
                { label: '女', value: '女' },
            ],
            style: {
                width: '100%'
            }
        },
        rules: [{ required: true, message: '请选择性别', trigger: 'blur' }]
    },
    serials: {
        component: 'ASelect',
        label: '可控设备',
        attrs: {
            allowClear: true,
            placeholder: '可控设备',
            options: SelfDeviceOptions,
            mode: 'multiple',
            style: {
                width: '100%'
            }
        },
        rules: [{ required: true, message: '请选择可控设备', trigger: 'blur' }]
    }
})

export const editSelfConfig = reactive({
    name: {
        component: 'AInput',
        label: '姓名',
        attrs: {
            allowClear: true,
            placeholder: '姓名',
            style: {
                width: '100%'
            }
        },
        rules: [{ required: true, message: '请输入姓名', trigger: 'blur' }]
    },
    departmentWard: {
        component: 'ACascader',
        label: '科室',
        attrs: {
            allowClear: true,
            placeholder: '科室',
            options: currentPermissionLeafArr,
            style: {
                width: '100%'
            }
        },
        rules: [{ required: true, message: '请选择科室', trigger: 'change' }]
    },
    sex: {
        component: 'ASelect',
        label: '性别',
        attrs: {
            options: [
                { label: '男', value: '男' },
                { label: '女', value: '女' },
            ],
            style: {
                width: '100%'
            }
        },
        rules: [{ required: true, message: '请选择性别', trigger: 'blur' }]
    },
    serials: {
        component: 'ASelect',
        label: '可控设备',
        attrs: {
            allowClear: true,
            placeholder: '可控设备',
            options: SelfDeviceOptions,
            mode: 'multiple',
            style: {
                width: '100%'
            }
        },
        rules: [{ required: true, message: '请选择可控设备', trigger: 'blur' }]
    }
})

export const columns = [
    {
        title: '序号',
        dataIndex: 'index',
        align: 'center',
        width: 80,
        fixed: 'left'
    },
    {
        title: '姓名',
        dataIndex: 'name',
        align: 'center',
        width: 150,
    }, {
        title: '性别',
        dataIndex: 'sex',
        align: 'center',
        width: 80,
    }, {
        title: '科室',
        dataIndex: 'departmentWard',
        width: 300,
        align: 'center',
        customRender: ({ record }: { record: any }) => record.illArea ? `${record.department}-${record.illArea}` : record.department
    }, {
        title: '可控设备',
        dataIndex: 'deviceNames',


        align: 'center',
        width: 200,
    },
    {
        title: '操作',
        dataIndex: 'action',
        align: 'center',
        width: 200,
    }
]